Skip to content

ext/curl: speed up tests - #23228

Open
Sjord wants to merge 3 commits into
php:masterfrom
Sjord:curl-faster-tests
Open

ext/curl: speed up tests#23228
Sjord wants to merge 3 commits into
php:masterfrom
Sjord:curl-faster-tests

Conversation

@Sjord

@Sjord Sjord commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

By waiting shorter for the server to be ready. In my setup, this takes it from 26 to 15 seconds for all curl tests.

The first check for output on stderr takes approximately 10ms, so we wait 20ms to make sure its ready. The second check for the open port typically succeeds immediately, so move the sleep to after we have tried.

Disable Expect: 100-continue to prevent libcurl's 1-second delay.

@Sjord
Sjord marked this pull request as ready for review August 12, 2026 13:04
@Sjord
Sjord requested a review from adoy as a code owner August 12, 2026 13:04
@Sjord

Sjord commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

@NickSdot Could you take a look at this?

@NickSdot NickSdot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Can confirm it's ~40% faster -- nice! Added one nit.

try {
// Give the server time to start
sleep(1);
for ($i = 0; $i < 100; $i++) {

@NickSdot NickSdot Aug 12, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for ($i = 0; $i < 100; $i++) {
for ($i = 0; $i < 50; $i++) {

Maybe 50 is enough? Would match the previous 1s; fsockopen already adds extra.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, 50 (or even 10 or 20) would work. 100 is just a number that's high but not infinite. In normal operation this loop will only iterate a couple of times, and 50 or 100 is never reached.

If you are worried about the time this test takes when the server fails to start, perhaps a better way is to get the server process status with proc_get_status and stop the test when the server is no longer running.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was just a nit; wouldn't over-complicate it personally. A server not starting would die out before we arrive here. It's rather for slower envs -- git history related to the server mentions some Travis CI (and other) edge cases. As you said, normally the max should not be hit -- since the 1s didn't flake 50ish is perhaps just fine.


if (CURLOPT_INFILE == $curl_option) {
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Expect:']);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disable Expect: 100-continue to prevent libcurl's 1-second delay.

May I ask where the 1 second delay come from?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expect 100-continue is a flow control mechanism that is not apparently not supported by the PHP development server. Curl waits one second for a 100-continue response and then continues anyway.

https://everything.curl.dev/http/post/expect100.html

Unfortunately, lots of servers in the world do not properly support the Expect: header or do not handle it correctly, so curl only waits 1000 milliseconds for that first response before it continues anyway.

You can avoid the wait entirely by using -H Expect: to remove the header

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sjord added 3 commits August 13, 2026 07:46
By waiting shorter for the server to be ready. In my setup, this takes
it from 26 to 15 seconds for all curl tests.

The first check for output on stderr takes approximately 10ms, so we
wait 20ms to make sure its ready. The second check for the open port
typically succeeds immediately, so move the sleep to after we have
tried.
Disable Expect: 100-continue to prevent libcurl's 1-second delay

Expect 100-continue is a flow control mechanism that is not apparently
not supported by the PHP development server. Curl waits one second for a
100-continue response and then continues anyway.

https://everything.curl.dev/http/post/expect100.html

> Unfortunately, lots of servers in the world do not properly support
the Expect: header or do not handle it correctly, so curl only waits
1000 milliseconds for that first response before it continues anyway.
> You can avoid the wait entirely by using -H Expect: to remove the header
@Sjord
Sjord force-pushed the curl-faster-tests branch from d8dd936 to 8fc637d Compare August 13, 2026 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants